/**********************************************************************************************/
/* FBL_I_Connection.h																		  */
/*                                                                       					  */
/* Copyright Paradigma, 1993-2006															  */
/* All Rights Reserved                                                   					  */
/**********************************************************************************************/

#ifndef __FBL_I_Connection_h
	#define __FBL_I_Connection_h
#pragma once

// FBL:
#include <VShared/FBL/publ/Headers/FBL.h>
#include <VShared/FBL/publ/Util_classes/FBL_EncryptionKey.h>
#include <VShared/FBL/publ/Interfaces/FBL_I_VNETW_Packet.h>

#include <VShared/FBL/publ/Interfaces/FBL_I_Compressor.h>

#include <VNetwork/Util_Classes/FBL_StubRegistry.h>

// FINAL:
#include <VShared/FBL/publ/Headers/FBL_pre_header.h>


/**********************************************************************************************/
FBL_Begin_Namespace


/**********************************************************************************************/
// Integer state variables.
//
enum EStateVariable {
	kFilesTransferMode,
	k__StateItemCountInteger
};


/**********************************************************************************************/
// State variable values (integer).
//
enum EStateVariableValue {

	/**	Files for operations like to/fromFile, import/export
		are sent over network connection. */
	kNetwork,

	/**	All files are taken from server (i.e. all received path 
		(as parameters of method) point to the files in server's 
		local file system. */
	kLocal,

	k__StateItemValueCountInteger
};


/**********************************************************************************************/
// server response codes
//
enum EResponseCode
{
	/* General purpose response codes */
	kOkResponse			= 'O',
	kErrorResponse		= 'E',	/* problem while executing command */
	kFatalResponse		= 'F',	/* problem while executing command - connection must be closed */
	kNoticeResponse		= 'N',	/* warning message */

	/* Start up cycle */
	kBackendKeyData		= 'K',

	/* Query cycle */
	kCompletedResponse	= 'C',	/* A SQL command completed normally */
	kCopyInResponse		= 'G',	/* The server is ready to copy data from the client */
	kCopyOutResponse	= 'H',	/* The server is ready to copy data to the client */


	/* Cursor cycle */
	kCursorResponse		= 'R',
	kStringResponse		= 'X',

	kResponse_Dummy = 0xFFFFFFFF
};


/**********************************************************************************************/
SMART_INTERFACE(I_IStream);
SMART_INTERFACE(I_OStream);


/**********************************************************************************************/
const ushort kDefaultPort 		= 15432;
const ushort kDefaultEmbPort 	= 15433;
const ushort kDefaultTimeout 	= 5;


/**********************************************************************************************/
SMART_INTERFACE(I_Connection);

/**********************************************************************************************/
// Factories of I_Connection. 
//
FBL_EXP I_Connection_Ptr CreateConnection( 
							const String& 	inHost,
							const String& 	inUserName,
							const String& 	inPassword,
							const char*		inEncoding = NULL,
							ushort			inPort = kDefaultPort,
							ushort 			inConnectTimeout = kDefaultTimeout,
							const char* 	inOptions = NULL );


/**********************************************************************************************/
// Interface I_Connection represents a physical connection between VClient and VServer. 
// 
interface FBL_SHARED_EXP_CLASS I_Connection : public I_Unknown
{
virtual						~I_Connection( void );

virtual	RemoteID			Open( void ) = 0;

							/** Closes existing connection.
								@param inGraceful - whether to send terminate 
									paket to the server (thus allowing it to close this 
									connection and free all it's used resources. 
									Practically always must be true (except some rare 
									cases not listed here). */
virtual	void				Close( bool inGraceful = true ) = 0;


	// ---------------------
	// Properties:

							/** Make this connection secure. Should be call before open.*/
virtual void				UseSSL( void ) = 0;

virtual bool				get_IsSingleByte( void ) const throw()  = 0;

		// <Stream>
virtual	FBL::I_IStream_Ptr	get_IStream( void ) throw() = 0;
virtual	FBL::I_OStream_Ptr	get_OStream( void ) throw() = 0;

		// <IsConnected> [r/o]
virtual	bool				get_IsConnected( void ) throw() = 0;

		// <HostName> [r/o]
virtual	const String&		get_HostName( void ) const throw() = 0;	//KEEPAS: mHostName

		// <UserName> [r/o]
virtual	const String&		get_UserName( void ) const throw() = 0; //KEEPAS: mUserName

		// <Password> [r/o]
virtual	const String&		get_Password( void ) const throw() = 0;	//KEEPAS: mPassword

		// <Port> [r/o]
virtual	ushort				get_Port( void ) const throw() = 0;

		// <ConnectionID> [r/o]
virtual	ulong				get_ID( void ) const throw() = 0;


		// <ResponseTimeout> [r/w]

							/// Returns server's response timeout.
virtual	ulong				get_ResponseTimeout( void ) const = 0;
							

							/** This method can be used to change server's 
								response timeout. You can change it to any 
								appropriate value before performing any 
								long time operation. 
								@param inTimeoutSec - the operation timeout in seconds. */
virtual	void				put_ResponseTimeout( ulong inTimeoutSec ) = 0;

virtual	void				HandleError(
								bool			inIsConnectionLevel,	/// If true - there is wire-level error.
								I_PacketRcv* 	inPacket = NULL,		
								bool			inThrowException = true ) = 0;

virtual	void				VerifyResponse( 
								I_PacketRcv& 	inPacket,
								bool			inThrowException,
								COMMAND_NAME	inCmd = kOkResponse ) const = 0;

		// <ResponseTimeout> [r/w]

virtual	const String&		get_ErrorDescription(  ) const throw() = 0;	//KEEPAS: mErrorDesc

virtual	const String&		get_FinalMessage( void ) const throw() = 0; //KEEPAS: mFinalMessage


		// <StateVariable> [r/w]
		
virtual EStateVariableValue	get_StateVariable( 
								EStateVariable inVarType ) const throw() = 0;

virtual void				put_StateVariable( 
								EStateVariable inVarType,
								EStateVariableValue inValue ) = 0;

virtual ClientStubRegistry* get_ClientStubRegistry( void ) = 0;

							// Each connection has own compressor.
virtual I_Compressor_Ptr	get_Compressor( void ) throw() = 0;

};


/**********************************************************************************************/
FBL_End_Namespace


/**********************************************************************************************/
#include <VShared/FBL/publ/Headers/FBL_post_header.h>


/**********************************************************************************************/
#endif //__FBL_I_Connection_h










